﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


namespace _013_WCFStreamServer
{

    public class FileUploader : IFileUploadContract
    {
        public void UploadFile(FileUploadMessage request)
        {
            try
            {
                Stream sourceStream = request.FileByteStream;
                string filePath = request.FileName;

                    //and save to output stream
                    const int bufferLen = 4096;
                    byte[] buffer = new byte[bufferLen];
                    int count = 0;
                    while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
                    {
                        Console.Write(Encoding.ASCII.GetString(buffer, 0, count));
                    }
                    sourceStream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
